/**
	@file utility.h
	@brief Contains auxiliary, frequently used functions without any relations to each other.
*/
#ifndef UTILITY_H
#define UTILITY_H

#include <stdexcept>
#include <QString>
#include <QColor>

/**
	@brief Converts QString to double securely (throws exception if conversion fails.)
	@param str string to be converted
	@return conversion's result (numeric type)
	@throws std::runtime_error exception with message describing the reason of throwing this exception's instance.
*/
inline double QStringToDouble(const QString& str) throw(std::runtime_error)
{
    bool success;
    double number = str.toDouble(&success);
    if(!success) throw std::runtime_error("Conversion txt to number has failed. Please enter valid number.");
    return number;
}
/**
	@brief Produces QString understandable by Qt's style-sheet that describes background color of QWidget.
	@param color desired background color
	@return QString understandable by Qt's style sheet.
*/
inline const QString getBgColorStyleSheet(const QColor& color)
{
    int r, g, b, a;
    color.getRgb(&r,&g,&b,&a);
    QString str("background-color: rgb(");
    str += QString::number(r) += QString(",") += QString::number(g) += QString(",") += QString::number(b) += QString(");");
    return str;
}

#endif // UTILITY_H
